<template>
<view class="container">
    <view class="tab">
      <view v-for="(item, index) in tab" :key="index" :style="'width:' + (100/(tab.length)) + '%;'" :class="(showTabIndex == index ? 'activeTab':'noneUse')" :data-id="index" @tap="bindTab">{{item.name}}</view>        
    </view>

    <swiper class="Tab_page" :current="showTabIndex" :style="'height: ' + sysHeight + 'px;'" @change="changeIndex"> 
      <swiper-item v-for="(tab, index) in tab" :key="index">
        <view class="swiperPageContainer">
          <view class="freshView">
            <view class="freshView_text">{{refreshText}}</view>
            <image src="https://image1.sansancloud.com/aikucun/2018_03/16/15/36/57_988.jpg?x-oss-process=style/preview_120"></image>
          </view>
           <scroll-view :style="'height: ' + sysHeight + 'px;'" class="tab_page_list" scroll-y upper-threshold="-60" lower-threshold="10" :data-index="index" @scroll="scrollEvent" @scrolltoupper="scrollTopToReflesh" @scrolltolower="scrollBottomToLoadMore">
            
            <view class="tab_page_list_container">
                <block v-if="!tab.List">  
                    <view class="noneList">没有相关订单</view>
                </block>
                <block v-else> 
                    <view class="cartContainer" v-for="(list, i) in tab.List" :key="i">
                       <view class="promotionNameItem" v-if="list.promotionName">
                          <view class="promotionNameLine"></view>
                          <view class="promotionName" :style="'background:' + setting.platformSetting.defaultColor"><text>{{list.promotionName}}</text></view>
                       </view>
                      <view class="cartShopName"> 
                        <view class="storageName" v-if="list.storageName&&list.orderType!=17"><text>{{list.storageName}}</text></view>
                        <view class="storageName" v-else-if="list.orderType==4"><text>充值订单</text></view>
                        <view class="storageName" v-else-if="list.orderType==18">
                          <text>{{list.attendBean?list.attendBean.attendCommitTitle:'报名表单'}}</text>
                        </view>
                        <view class="storageName" v-else-if="list.orderType==17">
                          <text>{{list.venuesCells?list.venuesCells[0].venues.name:'场馆预约'}}</text>
                        </view>
                        <view v-else><text></text></view>
                        <block v-if="list.easyStatusStr == '作废'"> 
                          <text class :style="'color:' + setting.platformSetting.defaultColor">已作废</text>
                        </block>
                        <block v-else-if="list.easyStatusStr == '完成'"> 
                          <text class :style="'color:' + setting.platformSetting.defaultColor">交易成功</text>
                        </block>
                        <block v-else-if="list.easyStatusStr == '待评价'"> 
                          <text class :style="'color:' + setting.platformSetting.defaultColor">待完成</text>
                        </block>
                        <block v-else-if="list.payType == 3&&list.payStatus==3"> 
                          <text class :style="'color:' + setting.platformSetting.defaultColor">已预付</text>
                        </block>
                        <block v-else>
                          <text class :style="'color:' + setting.platformSetting.defaultColor">{{list.easyStatusStr}}</text>
                        </block>
                      </view>

                      <view class="cartItems" v-for="(orderItem, index) in list.orderItems" :key="index" :data-orderNo="list.orderNo" @tap="lookMore" v-if="list.orderType!=17||list.orderType!=18">
                        <view class="itemCheckbox">
                          <image mode="aspectFill" :src="orderItem.itemIcon + '?x-oss-process=style/preview'"></image>
                        </view>
                        <view class="item_infomation">
                          <view class="item_infomation_name font1">{{orderItem.itemName}}</view>
                          
                          <view class="item_infomation_name2" v-if="!!orderItem.measureCartesianId">{{orderItem.measures}}</view>
                          <view class="item_infomation_nums"> 
                            <text class="flexCenter" style="color: #444;">￥{{orderItem.itemPrice}}</text>
                            <text class="flexCenter">x {{orderItem.itemCount}}</text>
                          </view>
                          <view class="item_infomation_money">
                            <view>
                                <!-- 单价:￥<text class="fontPrice">{{orderItem.itemPrice}}</text> -->
                                <view v-if="orderItem.needJifen>0">消耗积分:<text class="fontPrice">{{orderItem.needJifen}}</text></view>
                            </view>
                            <view class="orderNoStyle">
                              <view class="zitiOrder" v-if="list.mendianZiti==1">
                                <image class="orderTypeIcon" src="https://image1.sansancloud.com/xianhua/2019_1/7/15/54/51_620.jpg?x-oss-process=style/preview_120"></image>
                              </view>
                              <text>订单号:{{list.orderNo}}</text>
                            </view>
                            <view style="display:flex;flex-direction:row">归属门店:
                              <view style="display:flex">
                                【{{orderItem.sendStorageName}}】-【<text v-if="orderItem.mendianConfirm==0">未确认</text><text v-else>已确认</text>】
                              </view>
                            </view>
                          </view>
                        </view>
                      </view>
                      <!-- 场馆 -->
                      <view class="venues_cell_list" v-if="list.orderType==17" :data-orderNo="list.orderNo" @tap="lookMore">
                        <view class="venues_cell_item" :style="'background:' + setting.platformSetting.defaultColor" v-for="(venuesCellItem, index) in list.venuesCells[0].cells" :key="index">
                          <text class="venues_cell_item_time">{{venuesCellItem.startTimeStr}}-{{venuesCellItem.endTimeStr}}</text>
                          <text class="venues_cell_item_price">￥{{venuesCellItem.cellPrice}}</text>
                          <text class="circular"></text>
                        </view>
                      </view>
                      <!-- 表单提交的产品 -->
                      <view class="cartItems" v-for="(orderItem, index) in list.attendBean.attendMeasureList" :key="index" :data-orderNo="list.orderNo" @tap="lookMore" v-if="list.orderType==18">
                        <view class="itemCheckbox">
                          <image mode="aspectFill" v-if="list.attendBean.attendPlatformUserIcon" :src="list.attendBean.attendPlatformUserIcon + '?x-oss-process=style/preview'"></image>
                        </view>
                        <view class="item_infomation">
                          <view class="item_infomation_name font1">购买人：{{list.attendBean.attendPlatformUserName}}</view>
                          
                          <view class="item_infomation_name2 ">购买产品：{{orderItem.attendMeasureName}}</view>
                          <view class="item_infomation_nums"> 
                            <text class="flexCenter">x {{orderItem.buyCount}}</text>
                          </view>
                          <view class="item_infomation_money">
                            <view>单价:￥<text class="fontPrice">{{orderItem.attendPrice}}</text></view>
                            <view class="orderNoStyle">
                            <view class="zitiOrder" v-if="list.mendianZiti==1">
                                <image class="orderTypeIcon" src="https://image1.sansancloud.com/xianhua/2019_1/7/15/54/51_620.jpg?x-oss-process=style/preview_120"></image>
                              </view>
                              <text>订单号:{{list.orderNo}}</text>
                            </view>
                          </view>
                        </view>
                      </view>
                      <view class="butn_container">
                          <view class="order_type_icon">
                            
                            <view class="orderType" v-if="list.orderType==0">
                              <image class="orderTypeIcon" src="https://image1.sansancloud.com/sansancloud/2018_9/4/16/40/15_518.jpg?x-oss-process=style/preview_120"></image>
                            </view>
                            <view class="orderType" v-else-if="list.orderType==10">
                               <image class="orderTypeIcon" src="https://image1.sansancloud.com/sansancloud/2018_9/4/16/40/15_511.jpg?x-oss-process=style/preview_120"></image>
                            </view>
                            <view class="orderType" v-else-if="list.orderType==11">
                               <image class="orderTypeIcon" src="https://image1.sansancloud.com/sansancloud/2018_9/4/16/40/15_535.jpg?x-oss-process=style/preview_120"></image>
                            </view>
                            <view class="orderType" v-else-if="list.orderType==4">
                              <image class="orderTypeIcon" src="https://image1.sansancloud.com/sansancloud/2018_9/4/16/40/15_530.jpg?x-oss-process=style/preview_120"></image>
                            </view>
                            <view class="orderType" v-else-if="list.orderType==7">
                               <image class="orderTypeIcon" src="https://image1.sansancloud.com/sansancloud/2018_9/4/16/40/15_466.jpg?x-oss-process=style/preview_120"></image>
                            </view>
                            <view class="orderType" v-else-if="list.orderType==17">
                               <image class="orderTypeIcon" src="https://image1.sansancloud.com/xianhua/2019_7/3/10/51/56_79.jpg?x-oss-process=style/preview_120"></image>
                            </view>
                          </view>
                          <block>
                              <text>订单金额￥{{list.goodsAmount - list.youhuiAmount}}</text>
                              <text>（优惠￥{{list.youhuiAmount}}）</text>
                              <text>（运费￥{{list.yunfeiAmount}}）</text>
                          </block>
                      </view>
                      <!-- 订单类型不同，按钮不一样 &&list.easyStatus==3-->
                      <view v-if="list.easyStatus == 2" class="butn_container2">
                          <view></view>
                          <view class="butn_group">
                            <block v-if="list.payStatus!=3">
                                <text :data-order="list" class="butn_item" @tap="editOrder">编辑订单</text>
                                <text :data-order="list" class="butn_item" @tap="pay">立即付款</text>
                                <text :data-orderNo="list.orderNo" class="butn_item" :data-index="index" @tap="delectOrder">删除订单</text>
                            </block>
                            <block v-else>
                                <text :data-orderItem="list" :data-index="index" class="butn_item" @tap="payFinalPaymentFun">支付尾款￥{{list.remainAmount}}</text>
                            </block>
                          </view>
                      </view>
                      <view v-if="list.payStatus == 1 && list.orderStatus  == 1" class="butn_container2">
                        <view class="mendianZiti" v-if="list.mendianZiti==1" :data-link="'show_verification_code.html?code=' + list.orderNo + '&verifyScanType=2'" @click.stop="tolinkUrl">
                          <image class="ewmImg" src="https://image1.sansancloud.com/xianhua/2019_1/7/16/50/24_963.jpg"></image>
                          <text>核销码</text>
                        </view>
                        <view v-else></view>
                        <text :data-orderNo="list.orderNo" class="butn_item" :data-index="index" @tap="cancelOrder">取消订单</text>
                      </view>
                      <view v-if="list.easyStatus == 4" class="butn_container2">
                        <view></view>
                        <text :data-orderNo="list.orderNo" class="butn_item" :data-index="index" @tap="arriverOrder">确认收货</text>
                      </view>
                      <view v-if="list.payType == 0" class="butn_container2">
                        <view></view>
                        <text :data-orderNo="list.orderNo" class="butn_item" :data-index="index" @tap="cancelOrder">取消订单</text>
                      </view>
                      <view v-if="list.easyStatus == 5" class="butn_container2">
                          <view></view>
                          <view class="butn_group">
                            <text :data-orderNo="list.orderNo" class="butn_item" @tap="pingjiaOrder" v-if="list.isComment==0">评价</text>
                            <text :data-orderNo="list.orderNo" class="butn_item" :data-index="index" @tap="finishedOrder">完成订单</text>
                          </view>
                      </view>

                    </view>
                     <view v-if="tab.state.listEnd" class="dixian"> 我是有底线的 ~</view> 
                </block>
            </view>
          </scroll-view>
        </view>
         
      </swiper-item>
    </swiper>
</view>
</template>

<script>

export default {
  data() {
    return {
      orderList: [],
      reflesh: false,
      showTabIndex: 0,
      sysWidth: 320,
      sysHeight: 568,
      // tab: [],
      refreshText: '下拉刷新',
      opt: {},
      setting: "",
      loginUser: "",
      tab: [
          {
            name: '全部',
            getUrl: 'order_list_0.html',
            params: {
              easyStatusName: "全部订单",
              easyStatus: '0',
              page: 1
            },
            state: {
              scrollTop:0,
            },
            List: []
          },
          {
            name: '待付款',
            getUrl: 'order_list_2.html',
            params: {
              easyStatusName: "待付款",
              easyStatus: '2',
              page: 1
            },
            state: {
              scrollTop: 0,
            },
            List: []
          },
          {
            name: '待发货',
            getUrl: 'order_list_3.html',
            params: {
              easyStatusName: "待发货",
              easyStatus: '3',
              page: 1
            },
            state: {
              scrollTop: 0,
            },
            List: []
          },
          {
            name: '待收货',
            getUrl: 'order_list_4.html',
            params: {
              easyStatusName: "待收货",
              easyStatus: '4',
              page: 1
            },
            state: {
              scrollTop: 0,
            },
            List: []
          },
          {
            name: '已完成',
            getUrl: 'order_list_6.html',
            params: {
              easyStatusName: "已完成",
              easyStatus: '6',
              page: 1
            },
            state: {
              scrollTop: 0,
            },
            List: []
          },
        ],
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    this.opt = options;
    console.log(options);
    // this.setData({
    //   tab: this.tabBar
    // });
    this.dellOpt(options);
  },
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting,
      loginUser: getApp().globalData.loginUser,
      sysWidth: getApp().globalData.sysWidth,
      sysHeight: getApp().globalData.sysHeight-40
    });
  },
  methods: {
    /* 点击tab */
    bindTab: function (e) {
      var index = e.currentTarget.dataset.id;

      if (this.showTabIndex == index) {
        return;
      }

      this.setData({
        showTabIndex: index
      });
    },
    tolinkUrl: function (e) {
      console.log("tolinkUrl", e);
      let linkUrl = e.currentTarget.dataset.link;
      getApp().globalData.linkEvent(linkUrl);
    },

    /* 滑动事件 */
    changeIndex: function (e) {
      var index = e.detail.current;
      let tab = this.tab;
      let focusTab = tab[index];

      if (!focusTab.List || focusTab.List.length == 0) {
        this.getOrderList(focusTab, index, 1);
      }

      this.setData({
        showTabIndex: index
      });
    },

    /* 获取数据 */
    getOrderList: function (focusTab, index, fresh) {
      let params = focusTab.params;
      let tab = this.tab;
      var customIndex = getApp().globalData.AddClientUrl("/get_order_list.html", params);
      var that = this; 
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log('-----------orderList--------');
          console.log(res.data);
          focusTab.params.pageSize = res.data.pageSize;
          focusTab.params.curPage = res.data.curPage;
          focusTab.params.totalSize = res.data.totalSize;
          let result = res.data.result;

          for (let i = 0; i < result.length; i++) {
            result[i].remainAmount=(result[i].goodsAmount - result[i].youhuiAmount - result[i].payAmount).toFixed(2)
            if (result[i].attendBean&&result[i].attendBean.attendMeasureList) {
              result[i].attendBean.attendMeasureList = JSON.parse(result[i].attendBean.attendMeasureList);
            }
          }

          console.log("====result=======", result);

          if (fresh) {
            focusTab.List = [];
          }

          if (!result || result.length == 0) {
            focusTab.List = null;
          } else {
            focusTab.List = focusTab.List.concat(result);
          }

          tab[index] = focusTab;
          that.setData({
            tab: tab
          });
          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        },
        complete: function () {
          setTimeout(function () {
            that.loading = false;
          }, 2000);
          that.setData({
            refreshText: '下拉刷新'
          });
        }
      });
    },

    /* 下拉刷新 */
    scrollTopToReflesh: function (e) {
      console.log('粗发下拉事件');
      this.setData({
        refreshText: '松开手指即可刷新'
      });
      let index = e.currentTarget.dataset.index;
      let tab = this.tab;
      let focusTab = tab[index];

      if (!this.FreshIng) {
        this.FreshIng = true;
      } else {
        return;
      }
    },

    //刷新数据
    freshList(focusTab, index) {
      if (this.FreshIng) {
        this.FreshIng = false;
        console.log('mmmmmmmmmm   加载数据中   mmmmmmm');
        let that = this;
        focusTab.params.page = 1;
        this.getOrderList(focusTab, index, 1);
      }
    },

    scrollEvent: function (e) {
      let index = e.currentTarget.dataset.index;
      let tab = this.tab;
      let focusTab = tab[index];

      if (this.FreshIng && e.detail.scrollTop > -10) {
        console.log('mmmmmmmmmm   1   mmmmmmm');
        this.freshList(focusTab, index);
      }
    },

    /* 加载更多 */
    scrollBottomToLoadMore: function (e) {
      let that = this;
      console.log(this.loading);

      if (this.loading) {
        return;
      }

      this.loading = true;
      let index = e.currentTarget.dataset.index;
      let tab = this.tab;
      let focusTab = tab[index];

      if (focusTab.params.totalSize > focusTab.params.page * focusTab.params.pageSize) {
        ++focusTab.params.page;
        this.getOrderList(focusTab, index);
      } else {
        console.log('noMore');
        focusTab.state.listEnd = true;
        this.setData({
          tab: tab
        });
      }

      setTimeout(function () {
        that.loading = false;
      }, 2000);
    },

    /* 第一次加载 */
    dellOpt: function (options) {
      if (this.tab.length == 0) {
        return;
      }

      let easyStatus = options.easyStatus;

      if (!easyStatus) {
        easyStatus = 0;
      }

      let tab = this.tab;
      let index = 0;

      for (let i = 0; i < tab.length; i++) {
        if (tab[i].params.easyStatus == easyStatus) {
          index = i;
        }
      }

      if (index == 0) {
        this.getOrderList(tab[index], index);
      }

      this.setData({
        showTabIndex: index
      });
    },

    /* 支付 */
    pay: function (e) {
      var order = e.currentTarget.dataset.order;
      var that = this;
      console.log(order);
      getApp().globalData.payItem = order;
      this.setData({
        reflesh: true
      });
      wx.navigateTo({
        url: '/pages/submit_order_result/index'
      });
    },
    
    //支付尾款
    payFinalPaymentFun: function (e) {
        let that = this;
        let loginUser = getApp().globalData.loginUser;
        let orderItem = e.currentTarget.dataset.orderitem;
        let index = e.currentTarget.dataset.index;
        console.log(loginUser);
        let wxChatPayParam = {
          openid: loginUser.platformUser.miniOpenId,
          orderNo: orderItem.orderNo,
          app: 3
        };
        console.log(wxChatPayParam);
        getApp().globalData.payFinalPaymentFun(orderItem,wxChatPayParam,function(res){
            console.log("==payFinalPaymentFun==res",res)
              setTimeout(function () {
                let tab = that.tab;
                let focusTab = tab[index];
                focusTab.params.page = 1;
                that.getOrderList(focusTab, index, 1);
              }, 1000);
        })
    },
    /* 订单详细 */
    lookMore: function (e) {
      var orderNo = e.currentTarget.dataset.orderno;
      console.log(orderNo);
      this.setData({
        reflesh: true
      });
      wx.navigateTo({
        url: '/pages/order_detail/index?orderNo=' + orderNo
      });
    },

    /* 编辑订单 */
    editOrder: function (e) {
      var order = e.currentTarget.dataset.order;
      var orderNo = order.orderNo;
      console.log(order);
      this.setData({
        reflesh: true
      });
      console.log("===========tab======", this.tab);
      let list = this.tab;
      let data = null;

      for (let i = 0; i < list.length; i++) {
        //  console.log(list[i])
        for (let j = 0; j < list[i].List.length; j++) {
          //  console.log(list[i].List[j])
          if (orderNo == list[i].List[j].orderNo) {
            data = list[i].List[j];
            console.log("==========data========", data);
          }
        }
      }

      setTimeout(function () {
        wx.navigateTo({
          url: '/pages/edit_order/index?orderNo=' + data.orderNo
        });
      }, 200);
    },

    /* 取消订单 */
    cancelOrder: function (e) {
      var orderNo = e.currentTarget.dataset.orderno;
      var index = e.currentTarget.dataset.index;
      let tab = this.tab;
      let focusTab = tab[index];
      var that = this;
      wx.showModal({
        title: '提示',
        content: '取消订单',
        success: function (res) {
          if (res.confirm) {
            let param_post = {};
            param_post.orderNo = orderNo;
            var customIndex = getApp().globalData.AddClientUrl("/cancel_order.html", param_post, 'post');
            wx.request({
              url: customIndex.url,
              data: customIndex.params,
              header: getApp().globalData.headerPost,
              method: 'POST',
              success: function (res) {
                if (res.data.errcode == '0') {
                  console.log(res.data);
                  wx.showToast({
                    title: '取消订单成功',
                    icon: 'success',
                    duration: 1000
                  });
                  setTimeout(function () {
                    focusTab.params.page = 1;
                    that.getOrderList(focusTab, index, 1);
                  }, 1000);
                } else {
                  wx.showToast({
                    title: res.data.errMsg,
                    image: '/wxcomponents/images/icons/tip.png',
                    duration: 1000
                  });
                }
              },
              fail: function (res) {
                getApp().globalData.loadFail();
              }
            });
          } else if (res.cancel) {}
        }
      });
    },

    /* 删除订单 */
    delectOrder: function (e) {
      var orderNo = e.currentTarget.dataset.orderno;
      var index = e.currentTarget.dataset.index;
      let tab = this.tab;
      let focusTab = tab[index];
      var that = this;
      wx.showModal({
        title: '提示',
        content: '确认删除',
        success: function (res) {
          if (res.confirm) {
            let param_post = {};
            param_post.orderNo = orderNo;
            var customIndex = getApp().globalData.AddClientUrl("/order_unshow.html", param_post, 'post');
            wx.request({
              url: customIndex.url,
              data: customIndex.params,
              header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Cookie': getApp().globalData.cookie
              },
              method: 'POST',
              success: function (res) {
                if (res.data.errcode == '0') {
                  console.log(res.data);
                  wx.showToast({
                    title: '删除成功',
                    icon: 'success',
                    duration: 1000
                  });
                  setTimeout(function () {
                    focusTab.params.page = 1;
                    that.getOrderList(focusTab, index, 1);
                  }, 1000);
                } else {
                  wx.showToast({
                    title: res.data.errMsg,
                    image: '/wxcomponents/images/icons/tip.png',
                    duration: 1000
                  });
                }
              },
              fail: function (res) {
                getApp().globalData.loadFail();
              }
            });
          } else if (res.cancel) {}
        }
      });
    },

    /* 完成订单 */
    finishedOrder: function (e) {
      var orderNo = e.currentTarget.dataset.orderno;
      var index = e.currentTarget.dataset.index;
      let tab = this.tab;
      let focusTab = tab[index];
      var that = this;
      wx.showModal({
        title: '提示',
        content: '确认完成该订单？',
        success: function (res) {
          if (res.confirm) {
            let param_post = {};
            param_post.orderNo = orderNo;
            var customIndex = getApp().globalData.AddClientUrl("/order_finished.html", param_post, 'post');
            wx.request({
              url: customIndex.url,
              data: customIndex.params,
              header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Cookie': getApp().globalData.cookie
              },
              method: 'POST',
              success: function (res) {
                if (res.data.errcode == '0') {
                  console.log(res.data);
                  wx.showToast({
                    title: '操作成功',
                    icon: 'success',
                    duration: 1000
                  });
                  setTimeout(function () {
                    focusTab.params.page = 1;
                    that.getOrderList(focusTab, index, 1);
                  }, 1000);
                } else {
                  wx.showToast({
                    title: res.data.errMsg,
                    image: '/wxcomponents/images/icons/tip.png',
                    duration: 1000
                  });
                }
              },
              fail: function (res) {
                getApp().globalData.loadFail();
              }
            });
          } else if (res.cancel) {}
        }
      });
    },

    /* 订单评价 */
    pingjiaOrder: function (e) {
        console.log("===pingjiaOrder===",e)
      var orderNo = e.currentTarget.dataset.orderno;
      this.setData({
        reflesh: true
      });
      wx.navigateTo({
        url: '/pages/order_shop_comment/index?orderNo=' + orderNo
      });
    },

    /* 订单到货 */
    arriverOrder: function (e) {
      var orderNo = e.currentTarget.dataset.orderno;
      var that = this;
      console.log(orderNo);
      wx.showModal({
        title: '提示',
        content: '确认到货',
        success: function (res) {
          if (res.confirm) {
            let param_post = {};
            param_post.orderNo = orderNo;
            var customIndex = getApp().globalData.AddClientUrl("/order_received.html", param_post, 'post');
            wx.request({
              url: customIndex.url,
              data: customIndex.params,
              header: getApp().globalData.headerPost,
              method: 'POST',
              success: function (res) {
                console.log(res.data);

                if (res.data.errcode == '0') {
                  wx.showToast({
                    title: '订单已到货',
                    icon: 'success',
                    duration: 2000
                  });
                  setTimeout(function () {
                    wx.redirectTo({
                      url: '/pages/order_list_tab/index'
                    });
                  }, 2000);
                } else {
                  wx.showToast({
                    title: res.data.errMsg,
                    image: '/wxcomponents/images/icons/tip.png',
                    duration: 2000
                  });
                }
              },
              fail: function (res) {
                getApp().globalData.loadFail();
              }
            });
          } else if (res.cancel) {}
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>